package com.en.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.en.mapper.InfoMapper;
import com.en.mapper.WordMapper;
import com.en.model.Info;
import com.en.model.Word;
import com.en.service.WordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wuhaitao
 * @description 针对表【word】的数据库操作Service实现
 * @createDate 2023-11-19 15:57:51
 */
@Service
public class WordServiceImpl extends ServiceImpl<WordMapper, Word>
        implements WordService {
    @Autowired
    InfoMapper infoMapper;

    @Autowired
    WordMapper wordMapper;

    @Override
    public List<Word> getAllWord(Integer word_version) {
        LambdaQueryWrapper<Info> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Info::getEnKey, "word");

        Info info = infoMapper.selectOne(queryWrapper);

        Integer db_version = info.getVersion();

        if (db_version.equals(word_version)) {
            return null;
        }

//        获取word
        List<Word> wordList = wordMapper.selectList(null);


        return wordList;
    }

    @Override
    public Word getOneWordByWord(String word) {
        LambdaQueryWrapper<Word> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Word::getWord, word);

        Word wordObj = wordMapper.selectOne(queryWrapper);
        return wordObj;
    }

}




